/*
 * @Author: zhengzhuang
 * @since: 2019-12-23 11:04:37
 * @lastTime     : 2020-01-09 13:55:37
 * @LastAuthor   : zhengzhuang
 * @文件相对于项目的路径: /wangyueche_driver/lib/pages/intercity_car/index_intercity.dart
 * @message: 城际出行首页   IndexIntercity
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/model/get_peer_orders.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/widget/spinkit.dart';

class IndexIntercity extends StatefulWidget {
  @override
  _IndexIntercityState createState() => _IndexIntercityState();
}

class _IndexIntercityState extends State<IndexIntercity> {
  bool _updataState = true;

  Future _getTripRouteData() async {
    return await Request.getTripRouteData();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: RefreshIndicator(
        onRefresh: () async {
          setState(() {
            _updataState = true;
          });
        },
        color: Colors.black,
        child: FutureBuilder(
            future: _updataState ? _getTripRouteData() : '',
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              List _dataList = snapshot.data;
              if (snapshot.hasData) {
                if (_dataList.length == 0) {
                  return _noIntercityOrder();
                } else {
                  return ListView(
                    children:
                        _dataList.map((e) => _orderListContent(e)).toList(),
                  );
                }
              } else {
                return Spinkit();
              }
            }),
      ),
    );
  }

  /// 列表内容
  Widget _orderListContent(dataInfo) {
    GetPeerOrders modelData = GetPeerOrders.fromJson(dataInfo);
    return InkWell(
      child: Container(
        margin: EdgeInsets.only(
            left: ScreenUtil().setWidth(30.0),
            right: ScreenUtil().setWidth(30.0),
            top: ScreenUtil().setWidth(10.0),
            bottom: ScreenUtil().setWidth(5.0)),
        width: ScreenUtil().setWidth(690.0),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10.0)),
            boxShadow: <BoxShadow>[
              BoxShadow(
                  color: Colors.black26, blurRadius: ScreenUtil().setSp(20.0)),
            ]),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(30.0),
                  right: ScreenUtil().setWidth(30.0),
                  top: ScreenUtil().setWidth(30.0),
                  bottom: ScreenUtil().setWidth(20.0)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '城际指派订单',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(28.0),
                        fontWeight: FontWeight.w600),
                  ),
                  SizedBox(height: ScreenUtil().setWidth(30.0)),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(627.0),
                        height: ScreenUtil().setWidth(70.0),
                        decoration: BoxDecoration(
                            color: Color.fromARGB(255, 230, 230, 234),
                            borderRadius: BorderRadius.circular(
                                ScreenUtil().setWidth(10.0))),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: <Widget>[
                            Row(
                              children: <Widget>[
                                _blueDots(),
                                SizedBox(width: ScreenUtil().setWidth(10.0)),
                                Container(
                                    width: ScreenUtil().setWidth(200.0),
                                    child: Text('${modelData.orginPoint}',
                                        maxLines: 1,
                                        style: TextStyle(
                                            fontSize: ScreenUtil().setSp(34.0),
                                            color: Colors.black87,
                                            fontWeight: FontWeight.w400))),
                              ],
                            ),
                            Icon(Icons.trending_flat,
                                color: Colors.black,
                                size: ScreenUtil().setSp(60.0)),
                            Row(
                              children: <Widget>[
                                _orangeDots(),
                                SizedBox(width: ScreenUtil().setWidth(10.0)),
                                Container(
                                    width: ScreenUtil().setWidth(200.0),
                                    child: Text('${modelData.endPoint}',
                                        maxLines: 1,
                                        style: TextStyle(
                                            fontSize: ScreenUtil().setSp(34.0),
                                            color: Colors.black87,
                                            fontWeight: FontWeight.w400))),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        '${modelData.pickUpTime}出发',
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(26.0),
                            color: Color.fromARGB(255, 250, 144, 0)),
                      ),
                      MaterialButton(
                        color: Color.fromARGB(255, 78, 79, 95),
                        minWidth: ScreenUtil().setWidth(150.0),
                        height: ScreenUtil().setWidth(70.0),
                        child: Text('扫码收款',
                            style: TextStyle(
                                fontSize: ScreenUtil().setSp(26.0),
                                color: Colors.white)),
                        onPressed: () {
                          // print('modelData.id ===== ${modelData.id},----modelData.routerId ====== ${modelData.routerId},-------modelData.driverId===== ${modelData.driverId}');
                          NavigatorUtil.jump(context,
                              "/getOnByTicket?id=${modelData.id}&routerId=${modelData.routerId}&driverId=${modelData.driverId}");
                        },
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(30.0),
                  right: ScreenUtil().setWidth(30.0),
                  top: ScreenUtil().setWidth(30.0),
                  bottom: ScreenUtil().setWidth(30.0)),
              decoration: BoxDecoration(
                  border: Border(
                      top: BorderSide(
                          width: ScreenUtil().setWidth(1.5),
                          color: Colors.black12))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text('查看乘客',
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(28.0),
                      )),
                  Icon(Icons.navigate_next)
                ],
              ),
            )
          ],
        ),
      ),
      onTap: () =>
          NavigatorUtil.jump(context, '/flightPassengers?id=${modelData.id}'),
    );
  }

  /// 蓝色圆点
  Widget _blueDots() {
    return Container(
      width: ScreenUtil().setWidth(13.0),
      height: ScreenUtil().setWidth(13.0),
      decoration: BoxDecoration(color: Colors.blue, shape: BoxShape.circle),
    );
  }

  /// 橙色圆点
  Widget _orangeDots() {
    return Container(
      width: ScreenUtil().setWidth(13.0),
      height: ScreenUtil().setWidth(13.0),
      decoration: BoxDecoration(color: Colors.orange, shape: BoxShape.circle),
    );
  }

  /// 暂无城际订单
  Widget _noIntercityOrder() {
    return InkWell(
      child: Container(
        height: double.infinity,
        width: double.infinity,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              'assets/icon/assigningOrderIcon.png',
              width: ScreenUtil().setWidth(400.0),
              height: ScreenUtil().setWidth(400.0),
            ),
            Text('当前暂无城际订单, 点击我获取更新',
                style: TextStyle(
                    fontSize: ScreenUtil().setSp(28.0),
                    color: Color.fromARGB(255, 187, 189, 223))),
          ],
        ),
      ),
      onTap: () {
        setState(() {
          _updataState = true;
        });
      },
    );
  }

  /// 正在指派订单
  Widget _assigningOrder() {
    return Container(
      // height: double.infinity,
      width: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Image.asset(
            'assets/icon/assigningOrderIcon.png',
            width: ScreenUtil().setWidth(400.0),
            height: ScreenUtil().setWidth(400.0),
          ),
          Text('今日未有乘客',
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(28.0),
                  color: Color.fromARGB(255, 187, 189, 223))),
          // Text('请稍后...',
          //     style: TextStyle(
          //         fontSize: ScreenUtil().setSp(28.0),
          //         color: Color.fromARGB(255, 187, 189, 223))),
        ],
      ),
    );
  }
}
